<?php

function ubah_tgl($date)
{
    if($date == "sekarang")
    {
        $result = date("d") . " " . bulan_indo((int) date("n")) . " " . date("Y");
        return($result);
    }
    else if ($date !== NULL)
    {
        $tahun = substr($date, 0, 4);
        $bulan = substr($date, 5, 2);
        $tgl = substr($date, 8, 2);
        if ($bulan == "00" || $tahun == "0000" || $tgl == "00")
        {
            $result = "Format Tanggal Salah";
        }
        else
            $result = $tgl . " " . bulan_indo((int) $bulan) . " " . $tahun;
        return($result);
    }
    else
    {
        return "";
    }
}

function bulan_indo($bulan)
{
    $BulanIndo = array("Januari", "Februari", "Maret",
        "April", "Mei", "Juni",
        "Juli", "Agustus", "September",
        "Oktober", "November", "Desember");
    return $BulanIndo[(int) $bulan - 1];
}

function hari_indo($tgl)
{
    switch ($tgl)
    {
        case 1:
            $tgl = "Senin";
            break;
        case 2:
            $tgl = "Selasa";
            break;
        case 3:
            $tgl = "Rabu";
            break;
        case 4:
            $tgl = "Kamis";
            break;
        case 5:
            $tgl = "Jumat";
            break;
        case 6:
            $tgl = "Sabtu";
            break;
        case 7:
            $tgl = "Minggu";
            break;
    }
    return $tgl;
}

function hari_indo_huruf($hari)
{
    switch ($hari)
    {
        case 'Monday':
            $nama_hari = 'Senin';
            break;
        case 'Tuesday':
            $nama_hari = 'Selasa';
            break;
        case 'Wednesday':
            $nama_hari = 'Rabu';
            break;
        case 'Thursday':
            $nama_hari = 'Kamis';
            break;
        case 'Friday':
            $nama_hari = 'Jumat';
            break;
        case 'Saturday':
            $nama_hari = 'Sabtu';
            break;
        case 'Sunday':
            $nama_hari = 'Minggu';
            break;
        default:
            $nama_hari = "-";
            break;
    }
    return $nama_hari;
}

function Ubah_gelom($Ggelom)
{
    if ($Ggelom == 1)
    {
        return "I";
    }
    elseif ($Ggelom == 2)
    {
        return "II";
    }
    elseif ($Ggelom == 3)
    {
        return "III";
    }
    elseif ($Ggelom == 4)
    {
        return "IV";
    }
    elseif ($Ggelom == 5)
    {
        return "V";
    }
    elseif ($Ggelom == 6)
    {
        return "VI";
    }
    elseif ($Ggelom == 7)
    {
        return "VII";
    }
    elseif ($Ggelom == 8)
    {
        return "IIX";
    }
    elseif ($Ggelom == 9)
    {
        return "IX";
    }
    elseif ($Ggelom == 10)
    {
        return "X";
    }
}

function kopy_gambar($file_dari, $file_ke)
{
    $dst_width = 300;
    $dst_height = 400;

    $extensi = strtolower(end(explode(".", $file_dari)));
    if ($extensi == 'jpg' || $extensi == 'jpeg')
    {
        $im_src = imagecreatefromjpeg($file_dari);
    }
    elseif ($extensi == 'png')
    {
        $im_src = imagecreatefrompng($file_dari);
    }
    elseif ($extensi == 'gif')
    {
        $im_src = imagecreatefromgif($file_dari);
    }
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);
    //proses perubahan ukuran
    $im = imagecreatetruecolor($dst_width, $dst_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);

    if ($extensi == 'jpg' || $extensi == 'jpeg')
    {
        imagejpeg($im, $file_ke);
    }
    elseif ($extensi == 'png')
    {
        imagepng($im, $file_ke);
    }
    elseif ($extensi == 'gif')
    {
        imagegif($im, $file_ke);
    }

    imagedestroy($im_src);
    imagedestroy($im);
}

function date_database($date)
{
    $tahun = substr($date, -4);
    $bulan = substr($date, 3, 2);
    $tanggal = substr($date, 0, 2);

    return "$tahun-$bulan-$tanggal";
}

function date_database2($date)
{
    $tahun = substr($date, -4);
    $tanggal = substr($date, 3, 2);
    $bulan = substr($date, 0, 2);

    return "$tahun-$bulan-$tanggal";
}

function tglLengkap($date)
{
    if($date == NULL)
    {
        return hari_indo(date('N')) . ', ' . ubah_tgl("sekarang") . ' - ' . date('H:i:s');
    }
    return hari_indo(date('N', strtotime($date))) . ', ' . ubah_tgl($date) . ' - ' . date('H:i:s', strtotime($date));
}

function tglNoTime($date)
{
    if($date == NULL)
    {
        return hari_indo(date('N')) . ', ' . ubah_tgl("sekarang");
    }
    return hari_indo(date('N', strtotime($date))) . ', ' . ubah_tgl($date);
}

/* End of file fungsi.php */
/* Location: ./application/model/fungsi.php */